<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/tag.jsp"%>
<script type="text/javascript">
<%-- 
	var setting = {
		check: {
			enable: true
		},
		
	};

	var zNodes;
	var roleId=$("#roleId").val();

	$(function() {
		$.ajax({
			async : false,
			cache : false,
			type : 'POST',
			dataType : "json",
			url : "system/role/ajaxTree.do?roleId="+roleId,//请求的action路径  
			error : function() {//请求失败处理函数  
				alert('请求失败');
			},
			success : function(data) { //请求成功后处理函数。    
				zNodes = data; //把后台封装好的简单Json格式赋给treeNodes  
			}
		});
	});
	
	var zTree;
	$(document).ready(function() {
		$.fn.zTree.init($("#menutree"), setting, zNodes);
		var treeObj = $.fn.zTree.getZTreeObj("zTree");
	});
	--%>
	function onCheck(e, treeId, treeNode) {
		count();
	}
	function count() {
		var zTree = $.fn.zTree.getZTreeObj("menutree"),
		nodes = zTree.getCheckedNodes(true);
	}
	
	function save(){
		var zTree = $.fn.zTree.getZTreeObj("menutree"),
		nodes = zTree.getCheckedNodes(true);
		 var v = "";
         for(var i=0;i<nodes.length;i++) {
              v += "," + nodes[i].id
         }
		
		var par= "?v="+v;
		$("#treeForm").attr("action", "system/role/setPermessions.do"+par);
	}
	
</script>
<div class="bjui-pageContent">
	<form method="post" action="" id="treeForm"  class="pageForm" data-toggle="ajaxform">
		<div class="pageFormContent" data-layout-h="0">
		<input type="hidden" id="roleId" name="roleId" value="${roleId}"></input>
		<c:choose>
			<c:when test="${not empty menuList2}">
				<ul id="menutree" class="ztree ztree_main" data-toggle="ztree"  data-expand-all="true" 
					data-on-check="onCheck" data-check-enable="true">
					<c:forEach items="${menuList2}" varStatus="vs" var="menu1">
						<li data-id="${menu1.id}" data-pid="${menu1.pId}" data-checked="${menu1.checked}">${menu1.name}</li>
					</c:forEach>
				</ul>
			</c:when>
			<c:otherwise>
			</c:otherwise>
		</c:choose>
		</div>
		 <div class="bjui-footBar">
            <ul onclick="save()">
                <li><button type="button" class="btn-close">关闭</button></li>
                <li><button type="submit" class="btn-default">保存</button></li>
            </ul>
        </div>
	</form>
</div>